package com.ganbo.thread;

/**
 * Created by gan on 2020/5/19 8:30.
 */
public class DaemonDemo extends Thread {

    int count = 0;

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println(Thread.currentThread().getName() + "==============>" + (++count));
        }
    }

    public static void main(String[] args) throws InterruptedException {
        DaemonDemo d = new DaemonDemo();
        d.setDaemon(true);
        d.start();

        Thread.sleep(5000);

        System.out.println(Thread.currentThread().getName() + " 我离开了，守护线程也要停止了。");
    }
}
